<?php
/*
 * Copyright (c) 2022.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

namespace hiduoke\subscribe;

use app\common\model\wechat\WechatShare;
use think\Event;

class Timer
{
    public $times = [5, 10, 60];


    public function onTimer_5()
    {
    }

    public function onTimer_10()
    {
    }

    public function onTimer_60()
    {

    }

    public function onGlobalTimer_5()
    {
        WechatShare::handleShareTask();
    }

    public function onGlobalTimer_10()
    {
    }

    public function onGlobalTimer_60()
    {
    }

    public function subscribe(Event $event)
    {
        foreach ($this->times as $key => $value) {
            $eventName = 'onTimer_' . $value;
            $eventGlobalName = 'onGlobalTimer_' . $value;
            $event->listen($eventName, [$this, $eventName]);
            $event->listen($eventGlobalName, [$this, $eventGlobalName]);
        }
    }

}
